﻿using System;

namespace ParamTrans
{
    class Person
    {
        public string Name { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            // 引用类型的按值传递_修改属性值
            Console.WriteLine(" 引用类型的按值传递_修改属性值");
            Person person = new Person() { Name = "Old" };
            ChangeName(person);
            Console.WriteLine("调用后姓名是:"+person.Name);
            Console.WriteLine("____________________________________");

            // 引用类型的按值传递_修改对象
            Console.WriteLine(" 引用类型的按值传递_修改对象");
            person = new Person() { Name = "Old" };
            ChangePerson(person);
            Console.WriteLine("调用后姓名是:" + person.Name);
            Console.WriteLine("____________________________________");


            // 引用类型的按引用传递_修改属性值
            Console.WriteLine(" 引用类型的按引用传递_修改属性值");
            person = new Person() { Name = "Old" };
            ChangeNameRef(ref person);
            Console.WriteLine("调用后姓名是:" + person.Name);
            Console.WriteLine("____________________________________");


            // 引用类型的按引用传递_修改对象
            Console.WriteLine(" 引用类型的按引用传递_修改对象");
            person = new Person() { Name = "Old" };
            ChangePerson(ref person);
            Console.WriteLine("调用后姓名是:" + person.Name);
            Console.WriteLine("____________________________________");
        }

        // 引用类型的按值传递修改属性值
        static void ChangeName(Person person)
        {
            person.Name = "NewName";
            Console.WriteLine("函数调用中姓名是:" + person.Name);
        }
        // 引用类型的按值传递修改对象
        static void ChangePerson(Person person)
        {
            person = new Person();
            person.Name = "NewName";
            Console.WriteLine("函数调用中姓名是:" + person.Name);
        }
       
        // 引用类型的按引用传递修改属性值
        static void ChangeNameRef(ref Person person)
        {
            person.Name = "NewName";
            Console.WriteLine("函数调用中姓名是:" + person.Name);
        }
        // 引用类型的按引用传递修改对象
        static void ChangePerson(ref Person person)
        {
            person = new Person();
            person.Name = "NewName";
            Console.WriteLine("函数调用中姓名是:" + person.Name);
        }
    }
}